package org.aeon.gamechatnest.configuration;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;


/**
 * @author: MissingAeon
 * @date: 2024/5/9 18:41
 * @description:
 */
@OpenAPIDefinition(
        // API 信息
        info = @Info(
                title = "GameChatNest",
                version = "0.0.1",
                description = "GameChatNest项目API",
                contact = @Contact(name = "Aeon")
        )
        // security = @SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
        // externalDocs = @ExternalDocumentation(description = "参考文档", url = "")
)
// @SecurityScheme(
//         name = "Bearer Authentication",
//         type = SecuritySchemeType.HTTP,
//         bearerFormat = "JWT",
//         scheme = "bearer"
// )
@Configuration
public class OpenAPISecurityConfiguration {
    @Bean
    public OpenAPI customizeOpenAPI() {
        final String securitySchemeName = "验证token";
        return new OpenAPI()
                .addSecurityItem(new io.swagger.v3.oas.models.security.SecurityRequirement()
                        .addList(securitySchemeName))
                .components(new Components()
                        .addSecuritySchemes(securitySchemeName, new io.swagger.v3.oas.models.security.SecurityScheme()
                                .name(securitySchemeName)
                                .type(io.swagger.v3.oas.models.security.SecurityScheme.Type.HTTP)
                                .scheme("bearer")
                                .bearerFormat("JWT")));
    }
}
